##=============================================================================
## Appendix Figure 14
##=============================================================================

##-----------------
# clear environment
rm(list=ls())
options(stringsAsFactors = FALSE, scipen = 999)
# source("R/functions.R")

seed <- sample.int(.Machine$integer.max, 1)
set.seed(seed)

ipak <- function(pkg){new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("tidyverse", "hrbrthemes")

ipak(packages)

##---------
# Load data
#setwd("/Users/austinknuppe/Library/CloudStorage/Dropbox/Ukraine2022WartimeSurvey/Paper_peace/final_version_oct_2024/replication-scripts")
load("clean_ukraine_data.RData")

plot <- dat %>% 
  drop_na(ukr_no_nato) %>% 
  mutate(wave = case_when(
    wave == 0 ~ "July 2022 \n n = 1,890",
    wave == 1 ~ "February 2023 \n n = 1,908")) %>%
  mutate(wave = factor(wave, levels = c("July 2022 \n n = 1,890", 
                                        "February 2023 \n n = 1,908"))) %>% 
  group_by(wave, ukr_no_nato) %>% 
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% 
  mutate(ukr_no_nato = case_when(
    ukr_no_nato == 0 ~ "No",
    ukr_no_nato == 1 ~ "Yes")) %>% 
  mutate(ukr_no_nato = factor(ukr_no_nato, levels = c("No", "Yes")))

ggplot(plot, aes(x = wave, y = freq, fill = ukr_no_nato)) + 
  geom_bar(stat = "identity", position = position_dodge()) +
  labs(x = "", y = "Proportion", fill = "") +
  scale_y_continuous(labels = scales::percent) +
  scale_fill_grey() +
  theme_bw(base_size = 20) +
  theme(legend.position = "bottom", 
        legend.direction = "horizontal",
        legend.text = element_text(size = 20))

rm(list = ls())
##=============================================================================
## End of File
##=============================================================================